import {arrayToObject} from '../../../../assets/js/util.js' 
export default{
	    data() {
	      return{
			title:'实时充值流水',
			xlsxTitle:'',
			// 默认参数 和 URL
			SRC: '',
			DP: {
				p: '',
				f: ''
			},
			loading:false,
			searchable:false,
			form: {
			  	date: '',
				userid:'',
				roleid:''			
			},
			inputWidth:'220px',
			formLabelWidth: '100px',
	      	/*当前页显示数量*/
	      	pageSize:10,
	      	/*每页显示的数量*/
	      	pageSizes:[10, 20, 50, 100],
	      	/*dataTotal表数量*/
	      	dataTotal:0,
	      	/*表格数据*/
	      	realTimeServiceTableData:[],
	      	realTimeServiceTableDatas:[],
	      	/*realTimeServiceContent 的宽*/
	      	realTimeServiceContent:'100%',
	      	/*表的宽度*/
	      	realTimeServiceTableWidth: "100%",
	      	/*数据表头*/
			realTimeServiceTableHead:[
				{prop:'logtime',label:'时间',width:'auto'},
				{prop:'platform',label:'平台名称',width:'auto'},
				{prop:'serverid',label:'服务器名称',width:'auto'},
				{prop:'channel',label:'渠道名称',width:'auto'},
				{prop:'mac',label:'设备mac地址',width:'auto'},
				{prop:'userid',label:'账号ID',width:'auto'},
				{prop:'roleid',label:'角色ID',width:'auto'},
				{prop:'cashadd',label:'充值金额',width:'auto'},
				{prop:'rolelevel',label:'角色等级',width:'auto'},
				{prop:'totalcash',label:'付费总额',width:'auto'},
				{prop:'yuanbaoadd',label:'本次增加的元宝',width:'auto'},
				{prop:'flag',label:'是否首次付费',width:'auto'},
				{prop:'viplevel',label:'VIP等级',width:'auto'},
				{prop:'addtype',label:'充值类型',width:'auto'},
				{prop:'innerorderid',label:'内部订单号',width:'auto'},
				{prop:'outerorderid',label:'外部订单号',width:'auto'},
				{prop:'createtime',label:'内部订单创建时间',width:'auto'},
				{prop:'productid',label:'购买产品id',width:'auto'},
				{prop:'addtionmount',label:'赠送元宝(钻石)数',width:'auto'},
				{prop:'ip',label:'IP地址',width:'auto'}
	      	],
	      	rules: {
			},
	        /*分页器*/
	        currentPage: 1
	      }
	    },
		computed:{
			// xlsx(){
			// 	return this.title+'.xlsx'
			// }
		},
	    methods: {
			successFun(data) {
		      this.$message({
		        message: data,
		        type: 'success'
		      });
		    },
	    	errorFun(data) {
		      this.$message.error(data);
		    },
	    	dateChange(val){
	    		this.form.date = val
	    	},
	    	loads(){
	    		this.loading=!this.loading;	//加载中
				this.searchable = !this.searchable;//查询按钮不可用
	    	},
	    	reset(form) {
		    	this.$refs[form].resetFields();
		    },
		    search(form){
				this.$refs[form].validate((valid) => {
		        if (valid) {
		         	this.commitData()
		        } else {
		          this.errorFun('请完善输入的值！');
		          return false;
		        }
		      })
			},
			commitData(){
				this.realTimeServiceTableDatas=[];
				this.realTimeServiceTableData=[];
				let obj = `day=${this.form.date}&userid=${this.form.userid}&roleid=${this.form.roleid}`
				this.loads(); //加载 查询按钮不可用
				this.$http.jsonp(`${this.SRC}data/get.do?p=${this.DP.p}&f=${this.DP.f}&a=search`,{
					params:{'ps':obj},
				}).then(function(res){
					this.loads();
	    			var data =  JSON.parse(JSON.parse(res.body));
	    			if(parseInt(data.res) === 0){
	    				if(data.retlist.length==0){
	    					this.errorFun('查询结果为空！')
	    				}else{
	  						this.realTimeServiceTableDatas = data.retlist;
	    				}
		  			}else{
		  				this.errorFun(data.msg)
		  			}
		  			this.dataTotal = this.realTimeServiceTableDatas.length;
	    			this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
	    		})
			},
			// 表格下载
		  	excel(val) {
				this.xlsxTitle = val+"-"+this.form.date;
				this.downloadExl(this.realTimeServiceTableHead,this.realTimeServiceTableDatas,this.xlsxTitle,this.title);
		  		
		  	},
	    	/*分页器*/
			handleSizeChange(val) {
				this.pageSize = val;
				// this.getData(this.pageSize,this.currentPage)
				this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
			},
			handleCurrentChange(val) {
				this.currentPage = val;
				// this.getData(this.pageSize,this.currentPage)
				this.realTimeServiceTableData = this.realTimeServiceTableDatas.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
			},
	    	_dataPush(firstData,lastData){
				for (var key in firstData){
			        lastData.push({label:key,value:firstData[key]})
				}
	    	},
	    	/*设置初始值*/
	    	_init(){
	    		window.addEventListener('resize', function() {
	    			/*修改表格的宽度*/
	          		this.realTimeServiceTableWidth = document.body.clientWidth-240+"px";
	          		this.realTimeServiceContent = document.body.clientWidth-220+"px";
	        	}.bind(this))
	    	},
	    },
	    mounted() {
	     	this._init()
	     	// 初始化URL
			this.SRC = this.$store.getters.src;
			this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
			this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
	     	this.form.date = new Date();
	     	// this.getData(this.pageSize,this.currentPage)
	    }
	}